package initialize

import (
	"fmt"
	_ "github.com/mbobakov/grpc-consul-resolver"
	"go.uber.org/zap"
	"google.golang.org/grpc"
	"user_bff/global"
	user_pb "user_bff/user"
)

func InitSrcConn() {
	//负载均衡策略
	conn, err := grpc.Dial(
		fmt.Sprintf("consul://%s:%s/%s?wait=14s", global.ServerConfig.ConsulConfig.ConsulHost, global.ServerConfig.ConsulConfig.ConsulPort, "user_srv"),
		grpc.WithInsecure(),
		//负载均衡 轮询策略
		grpc.WithDefaultServiceConfig(`{"loadBalancingPolicy":"round_robin"}`),
	)
	if err != nil {
		zap.S().Panic(err)
		return
	}
	global.SrvConn = user_pb.NewUserClient(conn)

}
